// 导入axios
import axios from 'axios'
// 抽离公共地址
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

//请求在到达服务器之前，先会调用use中的这个回调函数来添加请求头信息
axios.interceptors.request.use(config => {
    //为请求头对象，添加token验证的Authorization字段
    config.headers.Authorization = window.sessionStorage.getItem("token")
    return config
})

// 登录请求
export const login_api = params => {
    return axios.post('login', params)
}

// 获取home的导航菜单
export const menus_api = params => {
    return axios.get('menus', params)
}

// 获取users用户数据列表
export const users_api = userParams => {
    return axios.get('users', { params: userParams })
}

// 改变用户状态
export const userState_api = params => {
    return axios.put(`users/${params.uid}/state/${params.type}`)
}

// 添加用户
export const userAdd_api = params => {
    return axios.post('users', params)
}

// 获取编辑用户的数据
export const editUserId_api = id => {
    return axios.get('users/' + id)
}

// 修改用户数据
export const editUser_api = params => {
    return axios.put('users/' + params.id, params)
}

// 删除用户数据
export const deleteUser_api = id => {
    return axios.delete('users/' + id)
}

// 获取用户角色
export const userRole_api = params => {
    return axios.get('roles', params)
}

// 分配用户角色
export const setUserRole_api = params => {
    return axios.put(`users/${params.id}/role`, params)
}

// 获取权限列表   type  传值 list 或 tree , list 列表显示权限, tree 树状显示权限
export const getRights_api = type => {
    return axios.get('rights/' + type)
}

// 删除指定权限
export const deleteRight_api = params => {
    return axios.delete(`roles/${params.roleId}/rights/${params.rightId}`, params)
}

// 角色授权
export const setRight_api = (roleId, params) => {
    return axios.post(`roles/${roleId}/rights`, params)
}

// 商品分类列表
export const getCate_api = params => {
    return axios.get('categories', { params })
}

// 商品分类添加
export const addCate_api = params => {
    return axios.post('categories', params)
}

// 分类参数列表
export const getParams_api = (id, params) => {
    return axios.get(`categories/${id}/attributes`, { params })
}

// 添加动态参数或者静态属性
export const addParams_api = (id, params) => {
    return axios.post(`categories/${id}/attributes`, params)
}

// 根据 ID 查询参数
export const getParamsById_api = (id, attrId, params) => {
    return axios.get(`categories/${id}/attributes/${attrId}`, params)
}

// 编辑提交参数
export const editParams_api = (id, attrId, params) => {
    return axios.put(`categories/${id}/attributes/${attrId}`, params)
}

// 删除参数
export const deleteParams_api = (id, attrId, params) => {
    return axios.delete(`categories/${id}/attributes/${attrId}`, params)
}

// 获取商品列表
export const getGoods_api = params => {
    return axios.get('goods', { params })
}

// 删除商品
export const deleteGoods_api = (id, params) => {
    return axios.delete(`goods/${id}`, params)
}

// 添加商品
export const addGoods_api = params => {
    return axios.post('goods', params)
}

// 获取订单列表
export const getOrders_api = params => {
    return axios.get('orders', { params })
}

// 查看物流信息
export const getProgress_api = (id, params) => {
    return axios.get(`/kuaidi/${id}`, params)
}

// 获取数据折线图
export const getReport_api = params => {
    return axios.get('reports/type/1', params)
}